import os
import unittest
import time
from BeautifulReport import BeautifulReport
from config.config import CASES_PATH,REPORTS_PATH
from HTMLTestRunner_cn import HTMLTestRunner

# 创建(实例化)测试套件
# suite = unittest.TestSuite()
suites = unittest.defaultTestLoader.discover(CASES_PATH, pattern="test_*.py")
# BeautifulReport(suites).report(filename="test_report.html",
#                               description="测试报告",
#                               report_dir=REPORT_PATH)
#将用例添加到测试套件
# suite.addTests()
# suite.addTests(suites)


#创建执行器，实例化测试执行
now = time.strftime("%Y%m%d%H%M%S")
report_name = os.path.join(REPORTS_PATH, f"crm_report_{now}.html")
with open(report_name, "wb") as f:
    runner = HTMLTestRunner(stream=f,
                            title="crm_test_report",
                            description="这是第一次运行",)
    runner.run(suites)

# runner = unittest.TextTestRunner()
#运行
# runner.run(suites)